﻿// CComboxAdv.cpp: 实现文件
//

#include "pch.h"
#include "Draw.h"
#include "CComboxAdv.h"


// CComboxAdv

IMPLEMENT_DYNAMIC(CComboxAdv, CComboBox)

CComboxAdv::CComboxAdv()
{

}

CComboxAdv::~CComboxAdv()
{
}


BEGIN_MESSAGE_MAP(CComboxAdv, CComboBox)
	ON_CONTROL_REFLECT(CBN_DROPDOWN, &CComboxAdv::OnCbnDropdown)
END_MESSAGE_MAP()



// CComboxAdv 消息处理程序




void CComboxAdv::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
	int nIndex = lpDrawItemStruct->itemID;
	CPen pen(PS_SOLID, nIndex + 1, RGB(0, 0, 0));

	CRect rcItem = lpDrawItemStruct->rcItem;
	// 处理不同状态（选中、禁用等）
	if (lpDrawItemStruct->itemState & ODS_SELECTED) {
		pDC->FillSolidRect(rcItem, RGB(120, 110, 115));  // 选中背景色
	}
	else {
		pDC->FillSolidRect(rcItem, RGB(255, 255, 255)); // 默认背景色
	}
	// 绘制文本和图标
	CString strText;
	GetLBText(lpDrawItemStruct->itemID, strText);
	pDC->SetBkMode(TRANSPARENT);
	pDC->SelectStockObject(DEFAULT_GUI_FONT);
	pDC->TextOut(rcItem.left + 30, rcItem.top + 2, strText);  // 文本偏移留出图标空间

	/*int nData = lpDrawItemStruct->itemData;
	CString str;
	str.Format(_T("%d"), nData);*/

	pDC->SelectObject(&pen);
	int y = (rcItem.bottom + rcItem.top) / 2;
	int x = rcItem.Height() / 2;
	pDC->MoveTo(x, y);
	pDC->LineTo(rcItem.Width() - x, y);
}


void CComboxAdv::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
{
	TRACE(_T("CComboxAdv::MeasureItem  %d\n"), lpMeasureItemStruct->CtlType);
	// 设置宽高
	if (lpMeasureItemStruct->CtlType == ODT_COMBOBOX) {
		lpMeasureItemStruct->itemHeight = 50;
		lpMeasureItemStruct->itemWidth = 80;
	}
}


int CComboxAdv::CompareItem(LPCOMPAREITEMSTRUCT lpCompareItemStruct)
{

	// TODO:  添加您的代码以确定指定项的排序顺序
	// 返回 -1 表示项 1 排在项 2 之前
	// 返回 0 表示项 1 和项 2 顺序相同
	// 返回 1 表示项 1 排在项 2 之后

	return 0;
}


void CComboxAdv::OnCbnDropdown()
{
	// TODO: 在此添加控件通知处理程序代码
}

